#ifndef __AKY_TASK_2_H__
#define __AKY_TASK_2_H__
#include "aky_program/aky_define.h"

#if (AKY_SWITCH_DEVELOP_BOARD == 1)
#define _4G_POWER_PORT GPIOD
#define _4G_POWER_PIN PIN12

#else
#define _4G_POWER_PORT GPIOD
#define _4G_POWER_PIN PIN11

#endif
#define _4G_POWER_PIN_INIT  GPIO_Init(_4G_POWER_PORT, _4G_POWER_PIN, 1, 0, 0, 0)
#define _4G_POWER_ON       GPIO_SetBit(_4G_POWER_PORT,_4G_POWER_PIN)
#define _4G_POWER_OFF      GPIO_ClrBit(_4G_POWER_PORT,_4G_POWER_PIN)

#define DEVICE_TYPE "906B"
#define SECRET_KEY "Q0w9E8r7T6y5U4i3O2p1A2s3"
#if 00
#define DEVICE_ID "861503074554909"

#else
#define DEVICE_ID IMEI

#endif

// #define DEVICE_TYPE "906M"
// #define SECRET_KEY "vXH5ldW2htJbTAOw0TvPo6y3"
// #define DEVICE_ID "04_02090101"

extern uint8_t  SignalQ;
extern uint8_t IMEI[16];
extern uint8_t IMSI[15];
extern uint8_t ICCID[20];


typedef enum
{
    TASK_2_at = 0,//发at
    TASK_2_ATE0W,
    TASK_2_check_cpin,//cpin? 查卡状态
    TASK_2_clk,//读取网络时间
    TASK_2_AT_CEREG,//注册
    TASK_2_cqs,//信号强度
    TASK_2_GSN,//IMEI
    TASK_2_QCCID,//QCCID
    TASK_2_CIMI,//CIMI
    TASK_2_Contextid,//配置上下文
    TASK_2_Contentype,//配置格式数据(使用JSON格式数据)
    TASK_2_Requestheader,//配置请求头
    TASK_2_Url_NUM,//申请加载网址位数
    TASK_2_Send_Url,//发送网址
    TASK_2_DATA_NUM,//申请数据包大小
    TASK_2_DATA_return_OK,//数据包返回值是否是OK
    TASK_2_QHTTPREAD,//查询是否上传成功
    TASK_2_get_fail,
    TASK_2_get_succes,

    TASK_2_undef,//

} e_aky_task_2_stat_t;

typedef struct
{
    e_aky_task_2_stat_t e_aky_task_2_stat; // 状态
    uint8_t CSQ;//信号强度
    uint8_t NOSIM;//没插卡
    uint8_t CEREG;//注册是否成功
    s_time_t s_get_time;//获取的时间
    uint8_t SendSYS;
    uint8_t SendDIA;
    uint8_t SendPUL;
    uint8_t SendPAD;
    uint8_t Flag_get_time;
    uint8_t flag_send_mem;
    uint8_t flag_send_result;
    uint8_t flag_at_ok;

    s_time_t s_send_time;//发送的时间

    char *Name;//姓名
    uint8_t Age;//年龄
    uint8_t Gender;//性别
    char *PhoneNo;//电话号码
    char *PaperNo;//证件号码
    uint8_t TrainMode;//训练模式
    uint16_t TrainPressure;//训练压力
    uint8_t Lng;//经度
    uint8_t Lat;//纬度
    char *DeviceAddress;//设备地址
    char *DeviceIp;//设备IP
    uint8_t StopFlag;//停止位

    uint8_t flag_is_full_dat;
//开始测量的数据
    int64_t MeasureTime_s;//测量时间
    uint8_t LeftError_s;//左臂报错
    uint16_t LeftSbp_s;//左臂高压
    uint16_t LeftDbp_s;//左臂低压
    uint8_t LeftPulseRate_s;//左臂心率
    uint8_t RightError_s;//右臂报错
    uint16_t RightSbp_s;//右臂高压
    uint16_t RightDbp_s;//右臂低压
    uint8_t RightPulseRate_s;//右臂心率
/////////////----------------------------------

//结束测量的数据
    int64_t MeasureTime;//测量时间
    uint8_t LeftError;//左臂报错
    uint16_t LeftSbp;//左臂高压
    uint16_t LeftDbp;//左臂低压
    uint8_t LeftPulseRate;//左臂心率
    uint8_t RightError;//右臂报错
    uint16_t RightSbp;//右臂高压
    uint16_t RightDbp;//右臂低压
    uint8_t RightPulseRate;//右臂心率
/////////////----------------------------------

    int64_t TrainStartTime;//训练开始时间
    int64_t TrainEndTime;//训练结束时间
    uint16_t AvgPressure;//平均压力
    uint8_t TrainError;//训练错误信息
    int64_t UpTime;//上传时间

} stru_aky_task_2_t;

typedef enum
{
    TASK2_GET_TIME = 0,
    TASK2_SEND_RESULT,
    TASK2_SEND_MEM,
} e_aky_Mcu_task2contrl;
extern stru_aky_task_2_t s_task_2;

#define aky_task_2_get_data() s_task_2

void aky_task_2_init(void);
void aky_task_2(void);
void aky_task_2_send_cmd(e_aky_Mcu_task2contrl cmd);
// stru_aky_task_2_t aky_task_2_get_data(void);
void c_json_test(void);
void Datatest(void);
int64_t timetostamp(s_time_t time);
void Data_consult(void);
uint8_t get_csq_val(void);
void task2_send_string(char *str);
uint8_t get_decode(char *decode_str);
s_time_t timestamp_to_s_time(int64_t timestamp);
void close_4g(void);
void opend_4g(void);
void send_4g_test_cmd(void);
uint8_t get_4g_test_ok_flag(void);
void aky_uart_2_init(void);

#endif